﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;
public partial class page_Introduction : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Session["ShowMessage"] = "用户未登录，请重新登录!";
            Session["Backurl"] = "Login.aspx";
            Response.Redirect("~/Message.aspx");
        }
        else
        {
            TarreOA.TarreOAModels.User sucessUser = (TarreOA.TarreOAModels.User)Session["user"];
            bool userFlag = false;
            if (sucessUser.PopedomGroup.PopedomList != null)
            {
                foreach (Popedom var in sucessUser.PopedomGroup.PopedomList)
                {
                    if (var.PopedomId == 53)
                    {
                        userFlag = true;
                        break;
                    }
                }
            }
            if (!userFlag)
            {
                Session["ShowMessage"] = "用户没有该权限，请与管理员联系!";
                Session["Backurl"] = "Right.aspx";
                Response.Redirect("~/Message.aspx");
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string id = Request["id"].ToString();
        //上传文件
        string name = FileUpload1.PostedFile.FileName.ToString();

        string filename = name.Substring(name.LastIndexOf("\\")+1);

        string hz = FileUpload1.PostedFile.ContentType;


        if (!hz.Equals("text/plain"))
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('只可以上传TXT类型的文件')</script>");
            return;
        }
        string path = Server.MapPath(".")+"\\flow_forms\\" + id+".txt";
        FileUpload1.SaveAs(path);

//读文件写入数据库
        string detail = "";
        string lineStr = "";
        StreamReader sr = new StreamReader(path, System.Text.Encoding.GetEncoding("gb2312"));
        //StreamReader re = File.OpenText(configfile+"\\upload\\a.txt");
        while ((lineStr = sr.ReadLine()) != null)
        {
            detail = detail + lineStr;
        }

        //Label1.Text =HttpUtility.UrlEncode(detail, System.Text.Encoding.UTF8);

        sr.Close();
        Flow_EditForm fef = new Flow_EditForm();
        fef.editFlowForm(id,detail);
    }
}
